package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.user.TbUserMapper;
import com.dongdongshop.pojo.user.TbUser;
import com.dongdongshop.pojo.user.TbUserExample;
import com.dongdongshop.service.user.UserService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private TbUserMapper tbUserMapper;
    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public int addUserAll(TbUser user) {
      return tbUserMapper.insertSelective(user);
    }

    @Override
    public List<TbUser> getByName(String username) {
        TbUserExample tbUserExample=new TbUserExample();
        TbUserExample.Criteria criteria = tbUserExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TbUser> tbUsers=tbUserMapper.selectByExample(tbUserExample);
        return tbUsers;
    }
/*
    @Override
    public Boolean phoneByCode(String phone, String code) {
       //获取redis中的key
        String phoneCode=""+phone+","+code+"";
        return redisTemplate.hasKey(phoneCode);
    }*/

    @Override
    public TbUser selectName(String username) {
        return tbUserMapper.selectName(username);
    }
}
